package com.wy17113.model.dao.impl;

import java.io.Serializable;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public abstract class HibernateBaseDao extends HibernateDaoSupport {
	@SuppressWarnings("unchecked")
	public abstract Class getEntityClass();

	public abstract String getEntityType();

	public void save(Serializable entity) {
		getHibernateTemplate().save(entity);
	}

	public void update(Serializable entity) {
		getHibernateTemplate().update(entity);
	}

	@SuppressWarnings("unchecked")
	public List getAll(int count, int start) {
		String hql = "from " + getEntityType() + " m ";
		Query q = getHibernateTemplate().getSessionFactory()
				.openSession().createQuery(hql);
		q.setMaxResults(count);
		q.setFirstResult(start);
		return q.list();
	}
}